//
//  UIButton+extension.swift
//  KySwiftPro
//
//  Created by fangyukui on 2017/10/17.
//  Copyright © 2017年 fangyukui. All rights reserved.
//

import UIKit

extension UIButton{
    convenience init(
        frame:CGRect? = CGRect.zero,
        nomalImg:String? = "",
        hlImg:String? = "",
        nomalbgColor:UIColor? = UIColor.clear,
        hlbgColor:UIColor? = UIColor.clear,
        nomalTextColor:UIColor? = UIColor.darkGray,
        hlTextColor:UIColor? = UIColor.darkGray,
        title:String? = "",
        target:Any,
        action:Selector) {
        if let frame = frame {
            self.init(frame: frame)
        }else{
            self.init()
        }
        setImage(UIImage(named: nomalImg ?? ""), for: .normal)
        setImage(UIImage(named: hlImg ?? ""), for: .highlighted)
        
        backgroundColor =  isSelected ? hlbgColor : nomalbgColor
        
        
        setTitle(title, for: .normal)
        
        setTitleColor(nomalTextColor, for: .normal)
        setTitleColor(hlTextColor, for: .highlighted);
        
        titleLabel?.font = UIFont.systemFont(ofSize: 16)
        
        
        addTarget(target, action: action, for: .touchUpInside)
        sizeToFit()
    }
}
